<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="/jquery.js"></script>
<body align="center">


<form th:action="@{/page}" method="post">
    书名：<input type="text" name="name" th:value="${bok.name}">
    作者：<input type="text" name="author" th:value="${bok.author}">
    类目：<input type="text" name="category" th:value="${bok.category}">
    <input type="submit" value="查询">
</form>
<form th:action="@{/del}" method="post" onsubmit="return submitForm()" align="center">
    <input type="submit" value="删除" onsubmit="return submitForm()">
    <a href="/yeAdd">新增</a>
    <table border="1" align="center">
        <tr>
            <td>选择</td>
            <td>编号</td>
            <td>书名</td>
            <td>库存</td>
            <td>价格</td>
            <td>类目</td>
            <td>说明</td>
            <td>图片</td>
            <td>作者</td>
            <td>已售</td>
            <td>操作</td>
        </tr>
        <tr th:each="book:${page.records}">
            <td><input type="checkbox" th:value="${book.id}" name="id"></td>
            <td th:text="${book.id}"></td>
            <td th:text="${book.name}"></td>
            <td th:text="${book.pnum}"></td>
            <td th:text="${book.price}"></td>
            <td th:text="${book.category}"></td>
            <td th:text="${book.description}"></td>
            <td><img th:src="${book.imgurl}" width="100px" alt="img"></td>
            <td th:text="${book.author}"></td>
            <td th:text="${book.sales}"></td>
            <td>
                <a th:href="@{/del(id=${book.id})}">删除</a>
                <a th:href="@{/yeUpdata(id=${book.id})}">修改</a>
            </td>
        </tr>
    </table>
    <div align="center">
        总页数：<span th:text="${page.pages}"></span>
        总记录数：<span th:text="${page.total}"></span>
        当前页：<span th:text="${page.current}"></span>
        当前页记录数：<span th:text="${page.size}"></span>
        <span th:if="${page.current>1}">
           <a th:href="@{/page(num=${page.current -1},name=${bok.name},author=${bok.author},category=${bok.category})}">上一页</a>
        </span>
        &nbsp;
        <span th:each="p:${#numbers.sequence(1,page.pages)}">
        <a th:href="@{/page(num=${p},book=${bok},name=${bok.name},author=${bok.author},category=${bok.category})}"
           th:text="${p}"></a>
        </span>
        <span th:if="${page.current<page.pages}">
        <a th:href="@{/page(num=${page.current+1},book=${bok},name=${bok.name},author=${bok.author},category=${bok.category})}">下一页</a>
        </span>
    </div>

</form>

<script>
    function submitForm() {
        if ($("input[name='id']:checked").length == 0) {
            alert("必须选择一个记录删除")
            return false
        }
        if (confirm("确定要删除吗？")) {
        } else {
            alert("已取消删除")
            return false
        }
    }
</script>
</body>
</html>